//
//  FoodOrderFormCell.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2021/9/15.
//  Copyright © 2021 zwb. All rights reserved.
//

import UIKit

class ZyaFoodOrderFormCell: UITableViewCell,operatable {
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        backgroundColor = Theme.backgroudColor
        selectionStyle = .none
        
        addSubview(bgView)
        bgView.addSubview(top)
        bgView.addSubview(bottom1)
        bgView.addSubview(bottom2)
        bgView.addSubview(bottom3)

        bgView.addSubview(rightButton)
        
        setupConstraints()
     }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var one:ZyaFoodOrderDetail? {
        didSet {
            if let one = one {
                
                if self.excuteType == .view {
                    rightButton.isHidden = true
                } else {
                    rightButton.isHidden = false

                }
                
//                if TenderAppear.shared.projectType == .awClient {
                    top.text = one.sName.unwrap + "  " + one.sSpec.unwrap + " " + one.sCompanyGoodsTreeNm.unwrap
//                } else {
//                    top.text = one.sName.unwrap
//                }
                let sumStr = one.sAuxNum.unwrap.isEmpty ? "0.000" : doubleTran(one.sAuxNum).threeZero
                let labelText = "数量" + sumStr
                let smokedLimitAttr1 = NSMutableAttributedString(string: labelText)
                smokedLimitAttr1.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.red, range: (labelText as NSString).range(of: sumStr))
                  bottom1.attributedText = smokedLimitAttr1
                
                let weightStr = one.sWeight.unwrap.isEmpty ? "0.000kg" : (doubleTran(one.sWeight).threeZero + "kg")

                let labelText2 = "重量" + weightStr
                let smokedLimitAttr2 = NSMutableAttributedString(string: labelText2)
                smokedLimitAttr2.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.red, range: (labelText2 as NSString).range(of: weightStr))
                 bottom2.attributedText = smokedLimitAttr2
                
                let moneyStr = one.sMoney.unwrap.isEmpty ? "0.00" : doubleTran(one.sMoney).twoZero
                bottom3.text = "￥ \(moneyStr)"

            }
        }
    }
    
    private func setupConstraints () {
        
        bgView.snp.makeConstraints { (maker) in
            maker.edges.equalTo(UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0))
        }
        
        top.snp.makeConstraints { make in
            make.left.equalTo(bgView).offset(12)
            make.top.equalTo(bgView).offset(5)
            make.right.equalTo(bgView).offset(-50)
        }
        bottom1.snp.makeConstraints { make in
            make.left.equalTo(top)
            make.top.equalTo(top.snp.bottom).offset(10)
        }
        bottom2.snp.makeConstraints { make in
            make.left.equalTo(top)
            make.top.equalTo(bottom1.snp.bottom).offset(10)
        }
        bottom3.snp.makeConstraints { make in
            make.right.equalTo(bgView).offset(-15)
            make.centerY.equalTo(bottom2)
        }
        
        rightButton.snp.makeConstraints { make in
            make.right.equalTo(bgView).offset(-10)
            make.width.equalTo(30)
            make.height.equalTo(30)
            make.top.equalTo(bgView).offset(10)
        }
        
    }
    
    lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        return view
    } ()
    
    
    
    lazy var top: UILabel = {
        let label = UILabel()
        label.text = "--"
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 15)
        label.numberOfLines = 2
        return label
    } ()
    lazy var bottom1: UILabel = {
        let label = UILabel()
        label.text = "--"
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 15)
        return label
    } ()
    lazy var bottom2: UILabel = {
        let label = UILabel()
        label.text = "--"
        label.textColor = Theme.textColor
        label.font = UIFont.systemFont(ofSize: 15)
        return label
    } ()
    lazy var bottom3: UILabel = {
        let label = UILabel()
        label.text = "--"
        label.textColor = .red
        label.font = UIFont.systemFont(ofSize: 15)
        return label
    } ()
    
    lazy var rightButton: UIButton = {
        let btn = UIButton()
        btn.isUserInteractionEnabled = false
        btn.setImage(#imageLiteral(resourceName: "fix"), for: UIControl.State())
        return btn
    } ()
    
    
}
